import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy';
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { dirResolver, DirResolverHelper } from 'vite-auto-import-resolvers'
import { chunkSplitPlugin } from 'vite-plugin-chunk-split';
import { resolve } from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ["vue", "vue-router", "pinia",],
      dirs:["src/http/"],
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      dirs: ['src/components/'],
      // 配置需要将哪些后缀类型的文件进行自动按需引入，'vue'为默认值
      extensions: ['vue'],
      // 解析组件，这里以 Element Plus 为例
      resolvers: [ElementPlusResolver()],
      // 生成components.d.ts
      dts: true,
      // 遍历子目录
      deep: true
    }),
    chunkSplitPlugin({
      // 指定拆包策略
      customSplitting: {
        'echarts': [/echarts/],
        'element': [/element/],
        'highlight': [/highlight/],
      }
    }),
    legacy({
      targets: ['defaults', 'not IE 11']
    })
  ],

  
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"), // 设置路径别名
    },
    extensions: [".js", ".ts", ".tsx", ".json"],
  },
  

  base: "./", // 打包后使用相对路径
  build: {
    outDir: "srtWebTool", // 打包输出位置
  }
})
